package woa.linkedlist.test20230206;

import woa.linkedlist.ListNode;

/**
 * @author wangpeng
 * @date 2023/2/6 19:06
 */
public class ReverseListProblem01 {

    public static ListNode reverse(ListNode head) {
        ListNode newHead = null;
        ListNode currNode = head;
        while (currNode != null) {
            ListNode next = currNode.next;
            currNode.next = newHead;
            newHead = currNode;
            currNode = next;
        }

        return newHead;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        head.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;

        System.out.println(reverse(head));
    }
}
